//
//  customerViewController.m
//  HJB
//
//  Created by jiezsoft.com on 14-10-10.
//  Copyright (c) 2014年 jiezsoft.com. All rights reserved.
//

#import "BusinessSupplierSupplierListViewController.h"
#import "HAODEsingleton.h"
#import "UIViewExt.h"
#import "HttpRequest.h"
#import "JSONKit.h"
#import "GenerateQRCodeViewController.h"
#import "BusinessSupplierEditSupplierViewController.h"
#import "UIImageView+WebCache.h"
#import "sxview.h"
#import "RDVTabBarController.h"
#import "MJRefresh.h"
#import "huiyuanCell.h"
#import "huiyuanDetailsViewController.h"
#import "TheLoginViewController.h"
//
#import "BusinessSupplierDetailViewController.h"
@interface BusinessSupplierSupplierListViewController ()<MBProgressHUDDelegate,UIGestureRecognizerDelegate,UINavigationControllerDelegate,UITextFieldDelegate,UISearchBarDelegate>
@property (strong, nonatomic) NSString *supField;
@property (strong, nonatomic) NSString*supSort;

@property(nonatomic,retain)UIDatePicker* da;

@end

@implementation BusinessSupplierSupplierListViewController

{
    UISearchBar *search;
    HAODEsingleton* commdity;
    MJRefreshHeaderView* _header;
    MJRefreshFooterView* _footer;
    NSMutableArray*address;
    
    NSMutableArray*createName;
    NSMutableArray*cityName;
    NSMutableArray*createDate;
    NSMutableArray*provinceName;
    NSMutableArray*regionName;
    NSMutableArray*supName;
    NSMutableArray*supplierId;
    NSMutableArray*consigneeAddr;
    NSMutableArray*consigneeName;
    NSMutableArray*consigneePhone;
    NSMutableArray*typeName;
    NSMutableArray*typeCode;
    NSMutableArray*isSingle;
    NSMutableArray*congzhicurrent;
    NSMutableArray*current;
    NSMutableArray*dataType;
    NSMutableArray *searchBeans;
    NSMutableArray*itemValue;
    NSMutableArray*itemName;
    NSMutableArray*items;
    UITextField*openTimeTextFied;
    UITextField*closeTimeTextFied;
    sxview*daogouView;
    UIView*view;
    NSString*baioqianshuju;
    UITableView *biaoqiantable_list;
    UITableView *table_list;
    UIScrollView*mainScroll;
    NSMutableArray* arrrss;
    NSMutableArray* biaoqianarrrss;
    NSMutableArray* biaoqianitemValue;
    UIButton*shaixuanBtn;
    NSString *result;
    int pageNumber;
    MBProgressHUD *progressHud;
    UIView* backview1;
    UIScrollView*myscrollView;
    NSString* sous;
    int pageNumber1;
    int pageNumber2;
    NSString*meiyousuos;
    UIView*view3;
    UITextField*searchTextField;
    UITextField*telTextFied;
    
    UITextField*gjzFied;
    UITextField*Salary1;
    UITextField*WorkExper1;
    UIView *view1;
    UIView *view2;
    UIButton*btn;
    UIButton*btn1;
    UIButton*btn2;
    UIView*myToolBar1;
    UIButton* sxBtn;
    UIButton* tianjiaBtn;
    UIButton* jiazai;
    float lastContentOffset;
    UIButton*sat;
    UIButton*sat1;
    UIButton*sat2;
    UIView*addView;
    BOOL saveAccount;
    int currentCount;
    UILabel*label;
    UIView*View;
    NSString* TotalCount;
    NSMutableArray *selectitemNameArray;
    NSMutableArray *selectitemValueArray;
    NSMutableArray *isCustom;
    NSMutableArray *isRange;
    NSMutableArray *biaoqianxuanzhong;
    NSString* zhongzhisx;
    UIButton*jiantouNormal;
}
@synthesize alt = alt;

-(void)BackAction:(UIButton *)sender{
    
    [searchTextField resignFirstResponder];
    
    [self.navigationController popViewControllerAnimated:YES];
    
    
}

- (void)viewDidDisappear:(BOOL)animated

{
    
    [super viewDidDisappear:animated];
    
    
    
    self.navigationController.delegate = nil;
    
}
-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    
    [[self rdv_tabBarController] setTabBarHidden:YES];
    self.navigationController.navigationBar.barStyle = UIBaselineAdjustmentNone;
    UILabel *lineLabel=[[UILabel alloc] initWithFrame:CGRectMake(0, 43,ScreenWidth, 1)];
    [lineLabel setBackgroundColor:[UIColor colorWithRed:238.0/255.0 green:238.0/255.0 blue:238.0/255.0 alpha:1.0]];
    [self.navigationController.navigationBar addSubview:lineLabel];
    [self.navigationController.navigationBar setTintColor:[UIColor whiteColor]];
    [[UINavigationBar appearance] setBarTintColor:Color];
    self.navigationController.navigationBarHidden=NO;
    
    [self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:@""] forBarMetrics:UIBarMetricsDefault];
    self.navigationController.navigationBar.shadowImage =[[UIImage alloc] init];
    
    UIImage* backImage = [UIImage imageNamed:@"fanhui"];
    CGRect backframe = CGRectMake(0,0,30,30);
    UIButton* backButton= [[UIButton alloc] initWithFrame:backframe];
    [backButton setBackgroundImage:backImage forState:UIControlStateNormal];
    backButton.titleLabel.textAlignment=NSTextAlignmentLeft;
    [backButton addTarget:self action:@selector(BackAction:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem* leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
    self.navigationItem.leftBarButtonItem = leftBarButtonItem;
    self.navigationController.delegate = self;
    self.navigationController.interactivePopGestureRecognizer.enabled = YES;
    self.navigationController.interactivePopGestureRecognizer.delegate = self;
    UIView* view11=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth*555/750, 65/2)];
    view11.backgroundColor=zuiqianhuicolor;
    UIButton *sxBtn1 = [[UIButton alloc] initWithFrame:CGRectMake( 2, 3, 50/2, 50/2)];
    [sxBtn1 setImage:[UIImage imageNamed:@"sousuo"] forState:UIControlStateNormal];
    //[sxBtn addTarget:self action:@selector(sou) forControlEvents:UIControlEventTouchUpInside];
    [view11 addSubview:sxBtn1];
    
    
    searchTextField = [[UITextField alloc] initWithFrame:CGRectMake(sxBtn1.right,1, ScreenWidth*400/750,65/2)];
    [searchTextField setBorderStyle:   UITextBorderStyleNone]; //外框类型
    searchTextField.placeholder = @"  名称/联系人/联系电话"; //默认显示的字
    searchTextField.font = [UIFont systemFontOfSize: 14];
    searchTextField.tag=22;
    searchTextField.returnKeyType = UIReturnKeyDone;
    searchTextField.clearButtonMode = UITextFieldViewModeWhileEditing; //编辑时会出现个修改X
    searchTextField.delegate = self;
    searchTextField.tintColor =tintCol;
    [view11 addSubview:searchTextField];
    self.navigationItem.titleView = view11;
    
    
    UIView* myToolBar=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, viewheight)];
    myToolBar.backgroundColor=jianpancolor;
    UIButton*  tubtnDone=[[UIButton alloc]initWithFrame:CGRectMake(logoX,logoY, logoheight, logowidth)];
    [tubtnDone setImage:[UIImage imageNamed:@""] forState:UIControlStateNormal];
    [tubtnDone addTarget:self action:@selector(OnTapDone) forControlEvents:UIControlEventTouchUpInside];
    [myToolBar addSubview:tubtnDone];
    UIButton*btnDone111=[[UIButton alloc]initWithFrame:CGRectMake(myToolBar.frame.size.width - 55, 12, 40, 16)];
    [btnDone111 setTitle:@"确定" forState:UIControlStateNormal];
    [btnDone111 setTitleColor:jianpancolor1 forState:UIControlStateNormal];
    btnDone111 .titleLabel .font=[UIFont systemFontOfSize:daxiao];
    [btnDone111 addTarget:self action:@selector(OnTapDone) forControlEvents:UIControlEventTouchUpInside];
    [myToolBar addSubview:btnDone111];
    myToolBar.alpha=alp;
    UIButton* dabtn=[[UIButton alloc]initWithFrame:CGRectMake(myToolBar.frame.size.width-60, 0, 60, 40)];
    [dabtn addTarget:self action:@selector(OnTapDone) forControlEvents:UIControlEventTouchUpInside];
    [myToolBar addSubview:dabtn];
    searchTextField.inputAccessoryView = myToolBar;
    self.supField=@"new";
    
    [sat1 setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    [sat setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    
    [jiantouNormal setImage:[UIImage imageNamed:@"jiantou_normal"] forState:UIControlStateNormal];
    
    [self add];
    saveAccount=YES;
}

-(void)OnTapDone{
    
    [searchTextField resignFirstResponder];
    
}


- (void)viewDidLoad
{
    
    [super viewDidLoad];
    
    [self addFooter];
    
    [self addheader];
    typeCode=[[NSMutableArray alloc]init];
    typeName=[[NSMutableArray alloc]init];
    items=[[NSMutableArray alloc]init];
    isSingle=[[NSMutableArray alloc]init];
    current=[[NSMutableArray alloc]init];
    congzhicurrent=[[NSMutableArray alloc]init];
    dataType=[[NSMutableArray alloc]init];
    
    
    selectitemNameArray=[[NSMutableArray alloc]init];
    selectitemValueArray=[[NSMutableArray alloc]init];
    isCustom=[[NSMutableArray alloc]init];
    isRange=[[NSMutableArray alloc]init];
 
    
    commdity=[HAODEsingleton shared];
    commdity.opentime=nil;
    commdity.closeTime=nil;
    commdity.content3=@"";
    
    UIView*tableHeaderView=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth, 40)];
    tableHeaderView.backgroundColor=zuiqianhuicolor;
    _table.tableHeaderView=tableHeaderView;
    
    sat=[[UIButton alloc]initWithFrame:CGRectMake(-10, 0, ScreenWidth/4, 40)];
    [sat setTitle:@"最新" forState:UIControlStateNormal];
    [sat setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    sat.titleLabel.textAlignment=NSTextAlignmentLeft;
    sat.titleLabel.font=[UIFont systemFontOfSize:15];
    [sat addTarget:self action:@selector(sat:) forControlEvents:UIControlEventTouchUpInside];
    [tableHeaderView addSubview:sat];
    
    sat1=[[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth/3, 0, ScreenWidth/3, 40)];
    [sat1 setTitle:@"金额" forState:UIControlStateNormal];
    sat1.titleLabel.font=[UIFont systemFontOfSize:15];
    [sat1 setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    [sat1 addTarget:self action:@selector(sat1:) forControlEvents:UIControlEventTouchUpInside];
    sat1.titleLabel.textAlignment=NSTextAlignmentCenter;
    [tableHeaderView addSubview:sat1];
    
    
    jiantouNormal=[[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth/2+20, 15, 10, 10)];
    [jiantouNormal setImage:[UIImage imageNamed:@"jiantou_normal"] forState:UIControlStateNormal];
    [jiantouNormal addTarget:self action:@selector(sat1:) forControlEvents:UIControlEventTouchUpInside];
    [tableHeaderView addSubview:jiantouNormal];
    
    
    
    shaixuanBtn=[[UIButton alloc]initWithFrame:CGRectMake(ScreenWidth*590/750,  0, 70,40)];
    [shaixuanBtn.layer setCornerRadius:2.0];
    [shaixuanBtn.layer setBorderWidth:0];
    [shaixuanBtn.layer setMasksToBounds:YES];
    [shaixuanBtn addTarget:self action:@selector(sxuan:) forControlEvents:UIControlEventTouchUpInside];
    CGColorSpaceRef colorSpace2 = CGColorSpaceCreateDeviceRGB();
    CGColorRef colorref2 = CGColorCreate(colorSpace2,(CGFloat[]){153/255.0,153/255.0, 153/255.0, 1.0   });
    [shaixuanBtn.layer setBorderColor:colorref2];//边框颜色
    [shaixuanBtn setTitle:@"     筛选" forState:UIControlStateNormal];
    shaixuanBtn.titleLabel.font=[UIFont systemFontOfSize:15];
    [shaixuanBtn setTitleColor:shenhuicolor forState:UIControlStateNormal];
    shaixuanBtn.titleLabel.textAlignment=NSTextAlignmentRight;
    [tableHeaderView addSubview:shaixuanBtn];
    
    sxBtn = [[UIButton alloc] initWithFrame:CGRectMake(3,5, 30, 30)];
    [sxBtn setImage:[UIImage imageNamed:@"shaixuan"] forState:UIControlStateNormal];
    [sxBtn addTarget:self action:@selector(sxuan:) forControlEvents:UIControlEventTouchUpInside];
    [shaixuanBtn addSubview:sxBtn];
    
    
    
    tianjiaBtn = [[UIButton alloc] initWithFrame:CGRectMake(30, 0.0, 60/2, 60/2)];
    [tianjiaBtn setImage:[UIImage imageNamed:@"tianjia"] forState:UIControlStateNormal];
    [tianjiaBtn addTarget:self action:@selector(addhuiyuan:) forControlEvents:UIControlEventTouchUpInside];
    UIBarButtonItem* myBtnBtn = [[UIBarButtonItem alloc] initWithCustomView:tianjiaBtn];
    self.navigationItem.rightBarButtonItem = myBtnBtn;
    
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSString* Token = [user objectForKey:@"tokenId"];
    if (Token ==nil) {
        Token=@"dd";
    }
    NSMutableDictionary *param = [NSMutableDictionary new];
    [param setValue:Token forKey:@"tokenId"];
    [param setValue:@"supplier" forKey:@"filterType"];
    NSLog(@"====%@",param);
    [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
    [HttpRequest requestData:@"Common/AdvancedFilterList" params:param success:^(BOOL isSuccess, SeverData *severDataDict) {
        if (isSuccess) {
            [Global hideProgressHUDInternal:self.view];
            NSLog(@"====－－－－－－－%@",severDataDict.dataDict);
            
            
            if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                
                
                NSMutableArray* arrr=[[NSMutableArray alloc]init];
                
                arrr=[severDataDict.dataDict objectForKey:@"DataLine"];
                
                for (NSDictionary* dicc in arrr )
                {
                    [typeName addObject:[dicc valueForKey:@"typeName"]];
                    [typeCode addObject:[dicc valueForKey:@"typeCode"]];
                    [items addObject:[dicc valueForKey:@"items"]];
                    [isSingle addObject:[dicc valueForKey:@"isSingle"]];
                    
                    [congzhicurrent addObject:[dicc valueForKey:@"current"]];
                    [current addObject:[dicc valueForKey:@"current"]];
                    [dataType addObject:[dicc valueForKey:@"dataType"]];
                    
                    for (NSDictionary* dicc1 in items )
                    {
                        [itemName addObject:[dicc1 valueForKey:@"itemName"]];
                        [itemValue addObject:[dicc1 valueForKey:@"itemValue"]];
                        
                    }
                    
                    
                }
                
                
                
            }else{
                [Global hideProgressHUDInternal:self.view];
                NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                [Global showTextHudSub:requestResultStr view:self.view];
            }
            
        }
        else
        {
            [Global hideProgressHUDInternal:self.view];
            
            [Global showTextHudSub:@"连接失败" view:self.view];
        }
        
    }];
    
    
}


-(void)addhuiyuan:(UIButton *)sender{
    
    
    commdity.memberId=@"";
    commdity.WeChatId=@"";
    
    commdity.selectTagCodeArray=nil;
    commdity.selectTagNameArray=nil;
    BusinessSupplierEditSupplierViewController *detailViewController = [[BusinessSupplierEditSupplierViewController alloc] init];
    [self.navigationController pushViewController:detailViewController animated:YES];
}
- (void)buttonAction:(UIButton *)button{
    
    [View removeFromSuperview];
    switch (button.tag)
    {
        case 1:
            
            if (button.tag==1) {
                
                [addView removeFromSuperview];
                
                commdity.memberId=@"";
                commdity.WeChatId=@"";
                BusinessSupplierEditSupplierViewController *detailViewController = [[BusinessSupplierEditSupplierViewController alloc] init];
                [self.navigationController pushViewController:detailViewController animated:YES];
                
            }
            break;
            
        case 2:
            
            if (button.tag==2) {
                
                [addView removeFromSuperview];
                
                GenerateQRCodeViewController*detailViewController = [[GenerateQRCodeViewController alloc] init];
                
                [self.navigationController pushViewController:detailViewController animated:YES];
                
                
                
            }
            
            break;
            
            
            
        default:
            break;
    }
}


- (BOOL)textFieldShouldReturn:(UITextField *)textField{
    [searchTextField resignFirstResponder];
    self.supField=@"";
    searchTextField.text=textField.text;
    
    [self add];
    
    return YES;
    
}
-(void)add{
    
    
    
    pageNumber = 1;
    
    _table.delegate=self;
    _table.dataSource=self;
    _table.separatorStyle=UITableViewCellSeparatorStyleNone;
    
    
    commdity=[HAODEsingleton shared];
    
    
    
    NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
    NSString* Token = [user objectForKey:@"tokenId"];
    if (Token ==nil) {
        Token=@"dd";
    }
    NSMutableDictionary *param = [NSMutableDictionary new];
    [param setValue:Token forKey:@"tokenId"];
    [param setValue:@"1" forKey:@"pageIndex"];
    [param setValue:@"20" forKey:@"pageSize"];
    [param setValue:self.supField forKey:@"supField"];
    
    [param setValue:_supSort forKey:@"supSort"];
    [param setValue:searchTextField.text forKey:@"keyWord"];
    
    if ([commdity.addhuiyuanViewController isEqualToString:@"选择"]) {
        
        [param setValue:@"Active" forKey:@"listType"];
        
        
        
    }
    [param setValue:searchBeans forKey:@"searchBeans"];
    if (searchBeans .count>0) {
        [sxBtn setImage:[UIImage imageNamed:@"shaixuan"] forState:UIControlStateNormal];
    }
    [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
    
    
    [HttpRequest requestData:@"Business/Supplier/SupplierList" params:param success:^(BOOL isSuccess, SeverData *severDataDict) {
        if (isSuccess) {
            
            NSLog(@"====%@",severDataDict.dataDict);
            if (searchBeans.count>0) {
                
               UIImage *img=[UIImage imageNamed:@"shaixuan_hight"];
                UIImage *tinted = [img rt_tintedImageWithColor:luseColor];
                [shaixuanBtn setTitleColor:luseColor forState:UIControlStateNormal];
                [sxBtn setImage:tinted forState:UIControlStateNormal];                
                
            }else{
                [shaixuanBtn setTitleColor:shenhuicolor forState:UIControlStateNormal];
                [sxBtn setImage:[UIImage imageNamed:@"shaixuan"] forState:UIControlStateNormal];
            }
            
            
            if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                [Global hideProgressHUDInternal:self.view];
                
                NSMutableArray* arrr=[[NSMutableArray alloc]init];
                
                arrr=[severDataDict.dataDict objectForKey:@"DataLine"];
                
                TotalCount=[severDataDict.dataDict objectForKey:@"TotalCount"];
                
                address= [[NSMutableArray alloc] init];
                cityName= [[NSMutableArray alloc] init];
                createDate= [[NSMutableArray alloc] init];
                createName= [[NSMutableArray alloc] init];
                provinceName= [[NSMutableArray alloc] init];
                regionName= [[NSMutableArray alloc] init];
                supName= [[NSMutableArray alloc] init];
                supplierId= [[NSMutableArray alloc] init];
                
                
                
                for (NSDictionary* dicc in arrr )
                {
                    [address addObject:[dicc valueForKey:@"address"]];
                    [cityName addObject:[dicc valueForKey:@"cityName"]];
                    [createDate addObject:[dicc valueForKey:@"createDate"]];
                    [createName addObject:[dicc valueForKey:@"createName"]];
                    [provinceName addObject:[dicc valueForKey:@"provinceName"]];
                    [regionName addObject:[dicc valueForKey:@"regionName"]];
                    [supName addObject:[dicc valueForKey:@"supName"]];
                    [supplierId addObject:[dicc valueForKey:@"supplierId"]];
                    
                    
                }
                
                
                [_table reloadData];
                
                
                
                
            }else{
                [Global hideProgressHUDInternal:self.view];
                if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==9999) {
                    
                    
                    TheLoginViewController*vc1=[[TheLoginViewController alloc] init];
                    
                    [self.navigationController pushViewController:vc1 animated:YES];
                    
                    
                    
                }
                
            }
            
        }
        else
        {
            [Global hideProgressHUDInternal:self.view];
            
            [Global showTextHudSub:@"连接失败" view:self.view];
        }
        
    }];
    
    
    
    
    
}
//下拉刷新最新数据
- (void)addheader
{
    
    //
    
    
    
    MJRefreshHeaderView* footer = [MJRefreshHeaderView header];
    footer.scrollView = _table;
    footer.beginRefreshingBlock = ^(MJRefreshBaseView* refreshView)
    {
        searchBeans=nil;
        commdity.content3=@"";
        [self add];
        
        
        [self performSelector:@selector(doneWithView:) withObject:refreshView afterDelay:3.0f];
        NSLog(@"%@--->正在刷新", refreshView.class);
    };
}



//上拉刷新数据
- (void)addFooter
{
    
    
    MJRefreshFooterView* footer = [MJRefreshFooterView footer];
    footer.scrollView = _table;
    footer.beginRefreshingBlock = ^(MJRefreshBaseView* refreshView)
    {
        
        NSLog(@"---------%d",pageNumber);
        NSLog(@"++++%d",TotalCount.intValue/5);
        
        if (TotalCount.intValue/20>=pageNumber) {
            pageNumber++;
            NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
            NSString* Token = [user objectForKey:@"tokenId"];
            if (Token ==nil) {
                Token=@"dd";
            }
            NSMutableDictionary *param = [NSMutableDictionary new];
            [param setValue:Token forKey:@"tokenId"];
            [param setValue:[NSString stringWithFormat:@"%d" ,pageNumber] forKey:@"pageIndex"];
            [param setValue:@"20" forKey:@"pageSize"];
            [param setValue:searchTextField.text forKey:@"keyWord"];
            [param setValue:searchBeans forKey:@"searchBeans"];
            [param setValue:self.supField forKey:@"supField"];
            if ([commdity.addhuiyuanViewController isEqualToString:@"选择"]) {
                
                [param setValue:@"Active" forKey:@"listType"];
                
                
                
            }
            
            [param setValue:_supSort forKey:@"supSort"];
            
            NSLog(@"====%@",param);
            [Global showIndeterminateHudSub:@"加载中，请稍后。。。" delay:30 view:self.view];
            
            
            [HttpRequest requestData:@"Business/Supplier/SupplierList" params:param success:^(BOOL isSuccess, SeverData *severDataDict) {
                if (isSuccess) {
                    NSLog(@"====%@",severDataDict.dataDict);
                    if ([[severDataDict.dataDict objectForKey:@"ResultInt"] integerValue]==0) {
                        [Global hideProgressHUDInternal:self.view];
                        
                        NSMutableArray* arrr=[[NSMutableArray alloc]init];
                        
                        arrr=[severDataDict.dataDict objectForKey:@"DataLine"];
                        
                        
                        for (NSDictionary* dicc in arrr )
                        {
                            [address addObject:[dicc valueForKey:@"address"]];
                            [cityName addObject:[dicc valueForKey:@"cityName"]];
                            [createDate addObject:[dicc valueForKey:@"createDate"]];
                            [createName addObject:[dicc valueForKey:@"createName"]];
                            [provinceName addObject:[dicc valueForKey:@"provinceName"]];
                            [regionName addObject:[dicc valueForKey:@"regionName"]];
                            [supName addObject:[dicc valueForKey:@"supName"]];
                            [supplierId addObject:[dicc valueForKey:@"supplierId"]];
                            
                        }
                        [_table reloadData];
                        
                        
                        
                        
                    }else{
                        [Global hideProgressHUDInternal:self.view];
                        NSString *requestResultStr=[severDataDict.dataDict objectForKey:@"ResultString"];
                        // [Global showTextHud:requestResultStr view:self.view];
                        [Global showTextHudSub:requestResultStr view:self.view];
                    }
                    
                }
                else
                {
                    [Global hideProgressHUDInternal:self.view];
                    
                    [Global showTextHudSub:@"连接失败" view:self.view];
                }
                
            }];
            
            
        }else{
            
            NSString *requestResultStr=@"没有更多数据了！";
            // [Global showTextHud:requestResultStr view:self.view];
            [Global showTextHudSub:requestResultStr view:self.view];
            
            
        }
        
        
        [self performSelector:@selector(doneWithView:) withObject:refreshView afterDelay:3.0f];
        NSLog(@"%@--->正在刷新", refreshView.class);
    };
}
- (void)doneWithView:(MJRefreshBaseView *)refreshView
{
    [_table reloadData];
    [refreshView endRefreshing];
}


- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
}
#pragma mark - Table view data source

- (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
{
    return 1;
}

- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    
    if (tableView == table_list) {
        return [typeCode count];
    }
    
    if (tableView == biaoqiantable_list) {
        return [biaoqianarrrss count];
    }
    
    return [supplierId count];
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    static NSString *CellIdentifier = @"Cell";
    
    huiyuanCell* cell = (huiyuanCell*)[tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil)
    {
        NSArray* nib = [[NSBundle mainBundle] loadNibNamed:@"huiyuanCell" owner:self options:nil];
        cell = [nib objectAtIndex:0];
    }
    cell.selectionStyle = UITableViewCellSelectionStyleNone;
    
    
    if (tableView == _table) {
        NSString *s2 =[NSString stringWithFormat:@"%@",  [supName objectAtIndex:indexPath.row]];
        UIFont *font2 = [UIFont systemFontOfSize:titleNemberfot];
        CGSize size2 = CGSizeMake(ScreenWidth-60, 2000);
        CGSize labelsize2 = [s2 sizeWithFont:font2 constrainedToSize:size2 lineBreakMode:NSLineBreakByCharWrapping];
        
        
        cell.UserName.text =[NSString stringWithFormat:@"%@", s2];
        cell.UserName.font=[UIFont systemFontOfSize:titleNemberfot];
        cell.UserName.textColor=[UIColor blackColor];
        cell.UserName.frame=CGRectMake(ScreenWidth*30/750, 20, labelsize2.width,titleNemberfot);
        
        
        
        
        cell.daogou.text=[NSString stringWithFormat:@"%@", @"员工"];
        cell.daogou.font=[UIFont systemFontOfSize:contenfot];
        cell.daogou.textColor=zhonghuiColor;
        cell.daogou.frame=CGRectMake(ScreenWidth*30/750,  50,  30, contenfot);
        
        
        NSString *s12 =[NSString stringWithFormat:@"%@",  [NSString stringWithFormat:@"%@", [createName objectAtIndex:indexPath.row]]];
        UIFont *font12 = [UIFont systemFontOfSize:contenfot];
        CGSize size12 = CGSizeMake(ScreenWidth-60, 2000);
        CGSize labelsize12 = [s12 sizeWithFont:font12 constrainedToSize:size12 lineBreakMode:NSLineBreakByCharWrapping];
        
        cell.daogouname.text=[NSString stringWithFormat:@"%@", [createName objectAtIndex:indexPath.row]];
        cell.daogouname.font=[UIFont systemFontOfSize:contenfot];
        cell.daogouname.textColor=shenhuicolor;
        cell.daogouname.frame=CGRectMake(cell.daogou.right,  50,  labelsize12.width+5, contenfot);
        
        cell.mendian.text=[NSString stringWithFormat:@"%@", @"登记日期"];
        cell.mendian.font=[UIFont systemFontOfSize:contenfot];
        cell.mendian.textColor=zhonghuiColor;
        cell.mendian.frame=CGRectMake(cell.daogouname.right+10,   50, 55, contenfot);
        
        if ([[createDate objectAtIndex:indexPath.row]length]>10) {
            NSRange range={0,10};
            NSString* string =[[NSString stringWithFormat:@"%@",[createDate objectAtIndex:indexPath.row]] substringWithRange:range];
            cell.mendianname.text=[NSString stringWithFormat:@"%@",string];
        }else{
            
            
            cell.mendianname.text=[NSString stringWithFormat:@"%@",[createDate objectAtIndex:indexPath.row]];
            
        }
        
        cell.mendianname.font=[UIFont systemFontOfSize:contenfot];
        cell.mendianname.textColor=shenhuicolor;
        cell.mendianname.frame=CGRectMake(cell.mendian.right,   50,  450*ScreenWidth/750, contenfot);
        
        
        
        
        cell.address.text=@"地址";
        cell.address.font=[UIFont systemFontOfSize:contenfot];
        cell.address.textColor=zhonghuiColor;
        cell.address.numberOfLines=1;
        cell.address.frame=CGRectMake(ScreenWidth*30/750,  68,30, contenfot);
        
        
        cell.address1.text=[NSString stringWithFormat:@"%@%@%@%@",[provinceName objectAtIndex:indexPath.row],[cityName objectAtIndex:indexPath.row],[regionName objectAtIndex:indexPath.row], [address objectAtIndex:indexPath.row]];
        cell.address1.font=[UIFont systemFontOfSize:contenfot];
        cell.address1.textColor=shenhuicolor;
        cell.address1.numberOfLines=1;
        cell.address1.frame=CGRectMake(cell.address.right,  68, ScreenWidth-40, contenfot);
        
        
        
        
        if (supplierId.count !=indexPath.row+1) {
            UILabel *lineLabel1=[[UILabel alloc] initWithFrame:CGRectMake(15,105-0.35, ScreenWidth-30, 0.35)];
            lineLabel1.backgroundColor=qianhuicolor;
            [cell.contentView addSubview:lineLabel1];
            
        }
        
        if (supplierId.count ==indexPath.row+1) {
            UILabel *lineLabel1=[[UILabel alloc] initWithFrame:CGRectMake(0, 105-0.35, ScreenWidth, 0.35)];
            lineLabel1.backgroundColor=qianhuicolor;
            [cell.contentView addSubview:lineLabel1];
            
        }
    }
    
    
    /////////////////////////////////
    
    
    
    
    if (tableView == biaoqiantable_list) {
        
        
        cell = [[huiyuanCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] ;
         cell.detailTextLabel.font=[UIFont systemFontOfSize:15];
        cell.textLabel.font=[UIFont systemFontOfSize:16];
        cell.textLabel.textColor=qianheicolor;
        cell.textLabel.text =[biaoqianarrrss objectAtIndex:indexPath.row];
        cell.saveAccount=YES;
        cell.xuanzeimage=[[UIImageView alloc] initWithFrame:CGRectMake(ScreenWidth-60-30, 17.5, 18, 18)];
        
        if  ([selectitemNameArray containsObject:[biaoqianarrrss objectAtIndex:indexPath.row]]){
            
            
            cell.xuanzeimage.image=[UIImage imageNamed:@"huiyuan_gou"];
            cell.saveAccount=NO;
            
        }
        
        
        [cell.contentView addSubview:cell.xuanzeimage];
        
        
        
        if (biaoqianarrrss.count !=indexPath.row+1) {
            UILabel *lineLabel1=[[UILabel alloc] initWithFrame:CGRectMake(15, 55-0.35, ScreenWidth-30-45, 0.3)];
            lineLabel1.backgroundColor=qianhuicolor;
            [cell.contentView addSubview:lineLabel1];
            
        }
        
        if (biaoqianarrrss.count ==indexPath.row+1) {
           UILabel *lineLabel1=[[UILabel alloc] initWithFrame:CGRectMake(15, 55-0.35, ScreenWidth-30-45, 0.3)];
            lineLabel1.backgroundColor=qianhuicolor;
            [cell.contentView addSubview:lineLabel1];
            
        }
        
    }
    
    
    //////////////////////////////////22222222222
    if (tableView == table_list) {
         cell.detailTextLabel.font=[UIFont systemFontOfSize:15];
        cell.textLabel.font=[UIFont systemFontOfSize:16];
        cell.textLabel.textColor=qianheicolor;
        if(commdity.content3.length> 0)
            
        {
            
            
            if  ([[typeName objectAtIndex:indexPath.row]isEqualToString:commdity.content2]){
                
                if (![commdity.content3 isEqualToString:@"自定义"]) {
                    cell.detailTextLabel.text =commdity.content3;
                    
                    for (int i = 0; i<[[items objectAtIndex:indexPath.row]count]; i++) {
                        
                        if  ([[[[items objectAtIndex:indexPath.row]objectAtIndex:i]objectForKey:@"itemName"] isEqualToString:commdity.content3]){
                            
                            [current replaceObjectAtIndex:indexPath.row withObject:[[items objectAtIndex:indexPath.row]objectAtIndex:i]];
                            
                        }else{
                            
                        }
                        
                    }
                    
                }else{
                    
                    cell.detailTextLabel.text =[NSString stringWithFormat:@"%@~%@",openTimeTextFied.text,closeTimeTextFied.text];
                    NSMutableDictionary *dic = [NSMutableDictionary dictionary];
                    
                    [dic setValue:[NSString stringWithFormat:@"%@",@"Y"]forKey:@"isCustom"];
                    [dic setValue:[NSString stringWithFormat:@"%@",@"Y"] forKey:@"isRange"];
                    [dic setValue:[NSString stringWithFormat:@"%@",@"自定义"] forKey:@"itemName"];
                    [dic setValue:[NSString stringWithFormat:@"%@",@"other"] forKey:@"itemValue"];
                    [dic setValue:openTimeTextFied.text forKey:@"minValue"];
                    [dic setValue:closeTimeTextFied.text forKey:@"maxValue"];
                    
                    [current replaceObjectAtIndex:indexPath.row withObject:dic];
                    
                    
                    
                }
                
                
            }else{
                
                if ([[typeName objectAtIndex:indexPath.row]isEqualToString:@"标签"]) {
                    
                    
                    if ([baioqianshuju isEqualToString:@"youshuju"]) {
                        
                        
                        NSString*  string=[[NSString alloc]init];
                        
                        for(int i = 0; i < selectitemNameArray.count; i++){
                            string = [string stringByAppendingString:[NSString stringWithFormat:@"%@ ",  selectitemNameArray[i]]];
                            
                        }
                        cell.detailTextLabel.text = string;
                    }else{
                        //                        cell.detailTextLabel.text = [[congzhicurrent objectAtIndex:indexPath.row]objectForKey:@"itemName"];
                    }
                    
                }else{
                    
                    
                    //                       cell.detailTextLabel.text = [[congzhicurrent objectAtIndex:indexPath.row]objectForKey:@"itemName"];
                }
                
                
            }
            
            
        }else{
            
            
            cell = [[huiyuanCell alloc] initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:CellIdentifier] ;
            cell.detailTextLabel.font=[UIFont systemFontOfSize:15];
            cell.textLabel.font=[UIFont systemFontOfSize:16];
            cell.textLabel.text = [typeName objectAtIndex:indexPath.row];
            cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
            
            
            
            if ([[isSingle objectAtIndex:indexPath.row]isEqualToString:@"N"]) {
                
                if ([baioqianshuju isEqualToString:@"youshuju"]) {
                    
                    
                    NSString*  string=[[NSString alloc]init];
                    
                    for(int i = 0; i < selectitemNameArray.count; i++){
                        string = [string stringByAppendingString:[NSString stringWithFormat:@"%@ ",  selectitemNameArray[i]]];
                        
                    }
                    cell.detailTextLabel.text = string;
                }else{
                    cell.detailTextLabel.text = [[congzhicurrent objectAtIndex:indexPath.row]objectForKey:@"itemName"];
                }
                
            }else{
                
                
                cell.detailTextLabel.text = [[congzhicurrent objectAtIndex:indexPath.row]objectForKey:@"itemName"];
            }
            
        }
        
        cell.detailTextLabel.textColor=luseColor;
        if (typeName.count !=indexPath.row+1) {
            UILabel *lineLabel1=[[UILabel alloc] initWithFrame:CGRectMake(15, 55-0.35, ScreenWidth-30-45, 0.3)];
            lineLabel1.backgroundColor=qianhuicolor;
            [cell.contentView addSubview:lineLabel1];
            
        }
        
        if (typeName.count ==indexPath.row+1) {
           UILabel *lineLabel1=[[UILabel alloc] initWithFrame:CGRectMake(15, 55-0.35, ScreenWidth-30-45, 0.3)];
            lineLabel1.backgroundColor=qianhuicolor;
            [cell.contentView addSubview:lineLabel1];
            
        }
        
    }
    
    
    return cell;
}





- (CGFloat) tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    if (tableView == table_list) {
        return  55;
    }
    if (tableView == biaoqiantable_list) {
        return  55;
    }
    
    return 105;
    
}


#pragma mark - Table view delegate


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    
    
    if (tableView == table_list) {
        
        
        
        UITableViewCell *cell=[tableView cellForRowAtIndexPath:indexPath];
        
        if ([cell.textLabel.text isEqualToString:@"标签"]) {
            
            NSMutableArray*arrrss1=[[NSMutableArray alloc]init];
            
            biaoqianarrrss=[[NSMutableArray alloc]init];
            biaoqianitemValue=[[NSMutableArray alloc]init];
            arrrss1=[[items objectAtIndex:indexPath.row] mutableCopy];
            
            for (int i = 0; i<arrrss1.count; i++) {
                [biaoqianarrrss addObject:[[[items objectAtIndex:indexPath.row] objectAtIndex:i] objectForKey:@"itemName"]];
                [biaoqianitemValue addObject:[[[items objectAtIndex:indexPath.row] objectAtIndex:i] objectForKey:@"itemValue"]];
            }
            
            biaoqiantable_list = [[UITableView alloc]initWithFrame:CGRectMake(50, 0, ScreenWidth-50, ScreenHeight) style:UITableViewStylePlain];
            biaoqiantable_list.delegate = self;
            biaoqiantable_list.dataSource = self;
            biaoqiantable_list.rowHeight = 60;
            biaoqiantable_list.separatorStyle=UITableViewCellSeparatorStyleNone;
            [self.window addSubview:biaoqiantable_list];
            
            
            UIView*Header=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth-50, NavHeight)];
            Header.backgroundColor=[UIColor whiteColor];
            biaoqiantable_list.tableHeaderView=Header;
            UILabel*line=[[UILabel alloc]initWithFrame:CGRectMake(0, NavHeight, ScreenWidth-50, 0.35)];
            line.backgroundColor=qianhuicolor;
            [Header addSubview:line];
            
            UILabel*title=[[UILabel alloc]initWithFrame:CGRectMake(0, 20, ScreenWidth-50, NavHeight-20)];
            title.text=@"标签";
            title.textAlignment=NSTextAlignmentCenter;
            [Header addSubview:title];
            
            UIButton*quxiao = [[UIButton alloc] initWithFrame:CGRectMake(5, 20, 50, NavHeight-20)];
            [quxiao setTitle:@"取消" forState:UIControlStateNormal];
            [quxiao setTitleColor:zhonghuiColor forState:UIControlStateNormal];
            quxiao.titleLabel.font=[UIFont systemFontOfSize:16];
            [quxiao addTarget:self action:@selector(biaoqianquxiao:) forControlEvents:UIControlEventTouchUpInside];
            [Header addSubview:quxiao];
            
            UIButton*chongzhi = [[UIButton alloc] initWithFrame:CGRectMake(ScreenWidth-50-60, 20, 50, NavHeight-20)];
            [chongzhi setTitle:@"确认" forState:UIControlStateNormal];
            [chongzhi setTitleColor:luseColor forState:UIControlStateNormal];
            chongzhi.titleLabel.font=[UIFont systemFontOfSize:16];
            [chongzhi addTarget:self action:@selector(biaoqianqueren:) forControlEvents:UIControlEventTouchUpInside];
            [Header addSubview:chongzhi];
            
            
        }else{
            
            
            commdity.content2=typeName[indexPath.row];
            
            [mainScroll removeFromSuperview];
            
            NSUserDefaults *user = [NSUserDefaults standardUserDefaults];
            NSString* Token = [user objectForKey:@"Token"];
            if (Token ==nil) {
                Token=@"dd";
            }
            NSMutableDictionary *param = [NSMutableDictionary new];
            [param setValue:Token forKey:@"Token"];
            
            mainScroll = [[UIScrollView alloc]initWithFrame:CGRectMake(50, 0, ScreenWidth-50, ScreenHeight)];
            mainScroll.delegate = self;
            mainScroll.userInteractionEnabled = YES;
            mainScroll.scrollEnabled = YES;
            mainScroll.backgroundColor=[UIColor whiteColor];
            [self.window addSubview:mainScroll];
            // 手势
            UITapGestureRecognizer *singleFingerOne = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(closeKeyBoad1)];
            singleFingerOne.numberOfTouchesRequired = 1; //手指数
            singleFingerOne.numberOfTapsRequired = 1; //tap次数
            singleFingerOne.delegate = self;
            [mainScroll addGestureRecognizer:singleFingerOne];
            UILabel*title=[[UILabel alloc]initWithFrame:CGRectMake(0, 20, ScreenWidth-50, NavHeight-20)];
            title.text=typeName[indexPath.row];
            title.textAlignment=NSTextAlignmentCenter;
            [mainScroll addSubview:title];
            
            UIButton*quxiao1 = [[UIButton alloc] initWithFrame:CGRectMake(5, 20, 50, NavHeight-20)];
            [quxiao1 setTitle:@"取消" forState:UIControlStateNormal];
            [quxiao1 setTitleColor:zhonghuiColor forState:UIControlStateNormal];
            quxiao1.titleLabel.font=[UIFont systemFontOfSize:16];
            [quxiao1 addTarget:self action:@selector(quxiao1:) forControlEvents:UIControlEventTouchUpInside];
            [mainScroll addSubview:quxiao1];
            UILabel*line=[[UILabel alloc]initWithFrame:CGRectMake(0, NavHeight-0.35, ScreenWidth-45, 0.35)];
            line.backgroundColor=qianhuicolor;
            [mainScroll addSubview:line];
            
            
            arrrss=[[NSMutableArray alloc]init];
            
            arrrss=[[items objectAtIndex:indexPath.row] mutableCopy];
            
            NSLog(@"%@",arrrss);
            if (arrrss.count>0) {
                
                for (int i = 0; i<arrrss.count; i++) {
                    
                    daogouView = [[sxview alloc]initWithFrame:CGRectMake(15, NavHeight+(55*i), ScreenWidth-45, 55)];
                    
                    daogouView.buttonView.titleLabel.textAlignment=NSTextAlignmentRight;
                    daogouView.buttonView.titleLabel.font=[UIFont systemFontOfSize:16];
                    daogouView.buttonView.contentHorizontalAlignment=UIControlContentHorizontalAlignmentLeft;
                    [daogouView.buttonView setTitle: [[[items objectAtIndex:indexPath.row] objectAtIndex:i] objectForKey:@"itemName"] forState:UIControlStateNormal];
                    daogouView.buttonView.backgroundColor=[UIColor whiteColor];
                    daogouView.buttonView.tag=i;
                    [daogouView.buttonView setTitleColor:[UIColor clearColor] forState:UIControlStateNormal];
                    [daogouView.buttonView setTitleColor:shenhuicolor forState:0];
                    
                    
                    
                    [mainScroll addSubview:daogouView];
                    
                    if ([[[[items objectAtIndex:indexPath.row] objectAtIndex:i] objectForKey:@"itemName"] isEqualToString:@"自定义"]) {
                        
                        if ([typeName[indexPath.row] isEqualToString:@"时间"]) {
                            
                            [daogouView.buttonView setTitleColor:luseColor forState:0];
                            
                            UIButton*login = [[UIButton alloc] initWithFrame:CGRectMake(0, ScreenHeight-48, ScreenWidth-45, 48)];
                            [login setTitle:@"确认" forState:UIControlStateNormal];
                            [login setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
                            login.backgroundColor=luseColor;
                            [login addTarget:self action:@selector(queren:) forControlEvents:UIControlEventTouchUpInside];
                            [mainScroll addSubview:login];
                            
                            
                            
                            
                            _da = [[UIDatePicker alloc] init];
                            [_da addTarget:self action:@selector(dateChanged:) forControlEvents:UIControlEventValueChanged];
                            _da.datePickerMode = UIDatePickerModeDate;
                            _da.backgroundColor=[UIColor whiteColor];
                            
                            
                            openTimeTextFied=[[UITextField alloc]initWithFrame:CGRectMake(50,  daogouView.bottom-55, 110,  55)];
                            openTimeTextFied.borderStyle = UITextBorderStyleNone;
                            openTimeTextFied.font = [UIFont systemFontOfSize: contenfot];
                            openTimeTextFied.textColor=[UIColor blackColor];
                            openTimeTextFied.autocapitalizationType = UITextAutocapitalizationTypeSentences;
                            openTimeTextFied.tag=2;
                            openTimeTextFied.placeholder = @"开始时间"; //默认显示的字
                            openTimeTextFied.delegate = self;
                            openTimeTextFied.text=commdity.opentime;
                            openTimeTextFied.textAlignment=NSTextAlignmentCenter;
                            [openTimeTextFied setUserInteractionEnabled:YES];
                            //                                  openTimeTextFied.clearButtonMode = UITextFieldViewModeWhileEditing;
                            [mainScroll addSubview:openTimeTextFied];
                            
                            UILabel* fuhao=[[UILabel alloc]initWithFrame:CGRectMake(openTimeTextFied.right, daogouView.bottom-55,15,55)];
                            fuhao.text=[NSString stringWithFormat:@"%@", @"～"];
                            fuhao.font=[UIFont systemFontOfSize:contenfot];
                            fuhao.textColor=[UIColor blackColor];
                            [mainScroll addSubview:fuhao];
                            
                            closeTimeTextFied=[[UITextField alloc]initWithFrame:CGRectMake(fuhao.right-5,  daogouView.bottom-55, 110,  55)];
                            closeTimeTextFied.borderStyle = UITextBorderStyleNone;
                            closeTimeTextFied.font = [UIFont systemFontOfSize: contenfot];
                            closeTimeTextFied.textColor=[UIColor blackColor];
                            closeTimeTextFied.autocapitalizationType = UITextAutocapitalizationTypeSentences;
                            closeTimeTextFied.tag=3;
                            closeTimeTextFied.placeholder = @"结束时间"; //默认显示的字
                            closeTimeTextFied.textAlignment=NSTextAlignmentCenter;
                            closeTimeTextFied.text= commdity.closeTime;
                            closeTimeTextFied.delegate = self;
                            [closeTimeTextFied setUserInteractionEnabled:YES];
                            //                                   closeTimeTextFied.clearButtonMode = UITextFieldViewModeWhileEditing;
                            [mainScroll addSubview:closeTimeTextFied];
                            
                            //                                  [_da setAccessibilityLanguage:@"Chinese"];
                            openTimeTextFied.inputView = _da;
                            closeTimeTextFied.inputView = _da;
                            
                        }
                        
                        
                    }else{
                        [daogouView.buttonView addTarget:self action:@selector(xuanzhong:) forControlEvents:UIControlEventTouchUpInside];
                    }
                    
                    if ([[[[items objectAtIndex:indexPath.row] objectAtIndex:i] objectForKey:@"itemName"] isEqualToString:cell.detailTextLabel.text]) {
                        
                       UIImageView*image=[[UIImageView alloc]initWithFrame:CGRectMake(ScreenWidth-50-60, 16.5, 18, 18)];
                        image.image=[UIImage imageNamed:@"huiyuan_gou"];
                        
                        [daogouView addSubview:image];
                        
                    }
                }
                
                [mainScroll setContentSize:CGSizeMake(ScreenWidth-45, daogouView.bottom)];
            }
            
            
            
            
        }
    }
    
    if (tableView == _table) {
        
        commdity.supplierId=supplierId[indexPath.row];
        //        commdity.memberId=supplierId[indexPath.row];
        //        commdity.adress=address[indexPath.row];
        //        commdity.Sex=sex[indexPath.row];
        //        commdity.Phone=phone[indexPath.row];
        commdity.supplier=supName[indexPath.row];
        
        commdity.consigneeAddr=consigneeAddr[indexPath.row];
        commdity.consigneeName=consigneeName[indexPath.row];
        commdity.consigneePhone=consigneePhone[indexPath.row];
        
        
        if ([commdity.addhuiyuanViewController isEqualToString:@"选择"]) {
            
            
            [self.delegate secondViewController:self
                                     updateText:commdity.memberId];
            
            [self.navigationController popViewControllerAnimated:YES];
            
            
        }else{
            
            commdity.gengxin=@"";
            BusinessSupplierDetailViewController *detailViewController = [[BusinessSupplierDetailViewController alloc] init];
            [self.navigationController pushViewController:detailViewController animated:YES];
        }
        
    }
    
    if (tableView == biaoqiantable_list) {
        
        UITableViewCell *cell=[tableView cellForRowAtIndexPath:indexPath];
        huiyuanCell *sharecell=(huiyuanCell *)cell;
        sharecell.saveAccount=! sharecell.saveAccount;
        
        if (!sharecell.saveAccount) {
            
            [selectitemNameArray addObject:[NSString stringWithFormat:@"%@",[biaoqianarrrss objectAtIndex:indexPath.row]]];
            [selectitemValueArray addObject:[biaoqianitemValue objectAtIndex:indexPath.row]];
            
            [isCustom addObject:@"N"];
            [isRange addObject:@"N"];
            
            
            sharecell.xuanzeimage.image=[UIImage imageNamed:@"huiyuan_gou"];
            
        }
        else{
            UITableViewCell *cell=[tableView cellForRowAtIndexPath:indexPath];
            huiyuanCell *sharecell=(huiyuanCell *)cell;
            
            
            sharecell.xuanzeimage.image=[UIImage imageNamed:@""];
            
            
            if (selectitemNameArray.count>0) {
                
                for (int i=0; i<selectitemNameArray.count; i++) {
                    
                    NSString *codeStr = [selectitemNameArray objectAtIndex:i];
                    if ([codeStr isEqualToString:[NSString stringWithFormat:@"%@",[biaoqianarrrss objectAtIndex:indexPath.row]]] ) {
                        
                        [selectitemNameArray removeObjectAtIndex:i];//从指定索引移除
                        [selectitemValueArray removeObjectAtIndex:i];//从指定索引移除
                        [isCustom removeObjectAtIndex:i];//从指定索引移除
                        [isRange removeObjectAtIndex:i];//从指定索引移除
                    }
                }
            }
        }
        
        
    }
    
}
//确认多标签
-(void)biaoqianqueren:(UIButton*)sender{
    
    biaoqianxuanzhong=[[NSMutableArray alloc]init];
    
    for (int i=0; i<selectitemNameArray.count; i++) {
        NSMutableDictionary *dic = [NSMutableDictionary dictionary];
        NSString *itemName1 = [selectitemNameArray objectAtIndex:i];
        NSString *itemValue1 = [selectitemValueArray objectAtIndex:i];
        NSString *typeName1 = @"N";
        NSString *dataType1 = @"N";;
        
        [dic setValue:[NSString stringWithFormat:@"%@",itemName1]forKey:@"itemName"];
        [dic setValue:[NSString stringWithFormat:@"%@",itemValue1] forKey:@"itemValue"];
        [dic setValue:[NSString stringWithFormat:@"%@",typeName1] forKey:@"isCustom"];
        [dic setValue:[NSString stringWithFormat:@"%@",dataType1] forKey:@"isRange"];
        
        [biaoqianxuanzhong addObject:dic];
    }
    
    
    zhongzhisx=@"youshuju";
    baioqianshuju=@"youshuju";
    
    biaoqiantable_list.frame=CGRectMake(ScreenWidth, 0, ScreenWidth-50, ScreenHeight);
    
    [table_list reloadData];
    
}
//取消多标签为空
-(void)biaoqianquxiao:(UIButton*)sender{
    
    baioqianshuju=@"";
    
    selectitemNameArray=[[NSMutableArray alloc]init];
    selectitemValueArray=[[NSMutableArray alloc]init];
    isCustom=[[NSMutableArray alloc]init];
    isRange=[[NSMutableArray alloc]init];
    biaoqiantable_list.frame=CGRectMake(ScreenWidth, 0, ScreenWidth-50, ScreenHeight);
    [table_list reloadData];
    
    
    
}
//取消单个标签
-(void)quxiao1:(UIButton*)sender{
    [openTimeTextFied resignFirstResponder];
    [closeTimeTextFied resignFirstResponder];
    [mainScroll removeFromSuperview];
    
}
-(void)queren:(UIButton*)sender{
    
    if ([ openTimeTextFied.text length] < 1)
    {
        [self showAlertMessage:@"请选择开始时间"];
    }
    else
    {
        
        if ([closeTimeTextFied.text length] <1)
        {
            [self showAlertMessage:@"请选择结束时间"];
        }
        else{
            
            commdity.opentime=openTimeTextFied.text;
            commdity.closeTime=closeTimeTextFied.text;
            [mainScroll removeFromSuperview];
            commdity.content3=@"自定义";
            [table_list reloadData];
            
            
        }}
    
    
}
//xuanzhong选中单个的数据
-(void)xuanzhong:(UIButton*)sender{
    zhongzhisx=@"shuju";
    commdity.content3=sender.titleLabel.text;
    [mainScroll removeFromSuperview];
    [table_list reloadData];
    commdity.opentime=nil;
    commdity.closeTime=nil;
    
    
}

//添加筛选类别
-(void)sxuan:(UIButton*)sender{
    
    
    if(commdity.content3.length> 0){
        
        
        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
        view=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 50, ScreenHeight)];
        view.backgroundColor=[UIColor blackColor];
        view.alpha=0.5;
        [self.window makeKeyAndVisible];
        [self.window addSubview:view];
        
        
        UITapGestureRecognizer *singleFingerOne = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(closeKeyBoad)];
        singleFingerOne.numberOfTouchesRequired = 1; //手指数
        singleFingerOne.numberOfTapsRequired = 1; //tap次数
        singleFingerOne.delegate = self;
        [view addGestureRecognizer:singleFingerOne];
        
        table_list.frame=CGRectMake(45, 0, ScreenWidth-45, ScreenHeight);
        [self.window addSubview:table_list];
        UIButton*login = [[UIButton alloc] initWithFrame:CGRectMake(45, ScreenHeight-48, ScreenWidth-45, 48)];
        [login setTitle:@"确认" forState:UIControlStateNormal];
        [login setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        login.backgroundColor=luseColor;
        [login addTarget:self action:@selector(querenleibie:) forControlEvents:UIControlEventTouchUpInside];
        [self.window addSubview:login];
        
        
    }else{
        
        
        self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
        view=[[UIView alloc]initWithFrame:CGRectMake(0, 0, 50, ScreenHeight)];
        view.backgroundColor=[UIColor blackColor];
        view.alpha=0.5;
        [self.window makeKeyAndVisible];
        [self.window addSubview:view];
        
        
        UITapGestureRecognizer *singleFingerOne = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(closeKeyBoad)];
        singleFingerOne.numberOfTouchesRequired = 1; //手指数
        singleFingerOne.numberOfTapsRequired = 1; //tap次数
        singleFingerOne.delegate = self;
        [view addGestureRecognizer:singleFingerOne];
        
        
//         saveAccount1=NO;
        table_list = [[UITableView alloc]initWithFrame:CGRectMake(45, 0, ScreenWidth-45, ScreenHeight) style:UITableViewStylePlain];

        table_list.delegate = self;
        table_list.dataSource = self;
        table_list.rowHeight = 60;
        table_list.separatorStyle=UITableViewCellSeparatorStyleNone;
        [self.window addSubview:table_list];
        
        
        UIView*Header=[[UIView alloc]initWithFrame:CGRectMake(0, 0, ScreenWidth-50, NavHeight)];
        Header.backgroundColor=[UIColor whiteColor];
        table_list.tableHeaderView=Header;
        UILabel*line=[[UILabel alloc]initWithFrame:CGRectMake(0, NavHeight, ScreenWidth-50, 0.35)];
        line.backgroundColor=qianhuicolor;
        [Header addSubview:line];
        
        UILabel*title=[[UILabel alloc]initWithFrame:CGRectMake(0, 20, ScreenWidth-50, NavHeight-20)];
        title.text=@"筛选";
        title.textAlignment=NSTextAlignmentCenter;
        [Header addSubview:title];
        
        UIButton*quxiao = [[UIButton alloc] initWithFrame:CGRectMake(5, 20, 50, NavHeight-20)];
        [quxiao setTitle:@"取消" forState:UIControlStateNormal];
        [quxiao setTitleColor:zhonghuiColor forState:UIControlStateNormal];
        quxiao.titleLabel.font=[UIFont systemFontOfSize:16];
        [quxiao addTarget:self action:@selector(quxiao:) forControlEvents:UIControlEventTouchUpInside];
        [Header addSubview:quxiao];
        
        UIButton*chongzhi = [[UIButton alloc] initWithFrame:CGRectMake(ScreenWidth-50-60, 20, 50, NavHeight-20)];
        [chongzhi setTitle:@"重置" forState:UIControlStateNormal];
        [chongzhi setTitleColor:luseColor forState:UIControlStateNormal];
        chongzhi.titleLabel.font=[UIFont systemFontOfSize:16];
        [chongzhi addTarget:self action:@selector(chongzhi:) forControlEvents:UIControlEventTouchUpInside];
        [Header addSubview:chongzhi];
        
        UIButton*login = [[UIButton alloc] initWithFrame:CGRectMake(45, ScreenHeight-48, ScreenWidth-45, 48)];
        [login setTitle:@"确认" forState:UIControlStateNormal];
        [login setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
        login.backgroundColor=luseColor;
        [login addTarget:self action:@selector(querenleibie:) forControlEvents:UIControlEventTouchUpInside];
        [self.window addSubview:login];
    }
}

-(void)chongzhi:(UIButton*)sender{
    searchBeans=nil;
    baioqianshuju=@"";
    [shaixuanBtn setTitleColor:shenhuicolor forState:UIControlStateNormal];
    [sxBtn setImage:[UIImage imageNamed:@"shaixuan"] forState:UIControlStateNormal];
    commdity.content3=@"";
    zhongzhisx=@"";
    current= [congzhicurrent mutableCopy];
    NSLog(@"----------%@",current);//重置值
    [table_list reloadData];
    
}
//取消筛选
-(void)quxiao:(UIButton*)sender{
    
    [openTimeTextFied resignFirstResponder];
    [closeTimeTextFied resignFirstResponder];
    [self.window makeKeyWindow ];
    self.window.hidden=YES;
    table_list.frame=CGRectMake(ScreenWidth, 0, ScreenWidth-45, ScreenHeight);
    
    
}
//确认筛选
-(void)querenleibie:(UIButton*)sender{
    
    [self.window makeKeyWindow ];
    self.window.hidden=YES;
    table_list.frame=CGRectMake(ScreenWidth, 0, ScreenWidth-45, ScreenHeight);
    
    searchBeans=[NSMutableArray array];
    
    for (int i=0; i<current.count; i++) {
        NSMutableDictionary *dic = [NSMutableDictionary dictionary];
        NSString *typeCode1 = [typeCode objectAtIndex:i];
        NSString *isSingle1 = [isSingle objectAtIndex:i];
        NSString *typeName1 = [typeName objectAtIndex:i];
        NSString *dataType1 = [dataType objectAtIndex:i];
        NSMutableArray* currentarray=[NSMutableArray array];
        [currentarray insertObject:[current objectAtIndex:i] atIndex:0];
        [dic setValue:[NSString stringWithFormat:@"%@",typeCode1]forKey:@"typeCode"];
        [dic setValue:[NSString stringWithFormat:@"%@",isSingle1] forKey:@"isSingle"];
        [dic setValue:[NSString stringWithFormat:@"%@",typeName1] forKey:@"typeName"];
        [dic setValue:[NSString stringWithFormat:@"%@",dataType1] forKey:@"dataType"];
        
        if ([isSingle1 isEqualToString:@"N"]) {
            
            
            if ([baioqianshuju isEqualToString:@"youshuju"]) {
                
                
                [dic setValue:biaoqianxuanzhong forKey:@"items"];
                
                
            }else{
                
                [dic setValue:currentarray forKey:@"items"];
                
            }
            
            
        }else{
            
            [dic setValue:currentarray forKey:@"items"];
            
        }
        
        [searchBeans addObject:dic];
    }
    
    NSLog(@"====%@",searchBeans);
    
    
    if ([zhongzhisx isEqualToString:@""]) {
        searchBeans=nil;//重置无数据
    }
    
    [self add];
    
    
}



-(void)closeKeyBoad1{
    [openTimeTextFied resignFirstResponder];
    [closeTimeTextFied resignFirstResponder];
}
-(void)closeKeyBoad{
    [openTimeTextFied resignFirstResponder];
    [closeTimeTextFied resignFirstResponder];
    [self.window makeKeyWindow ];
    self.window.hidden=YES;
    
    table_list.frame=CGRectMake(ScreenWidth, 0, ScreenWidth-45, ScreenHeight);
    saveAccount=YES;
    [View removeFromSuperview];
    [addView removeFromSuperview];
    
}


-(void)sat:(UIButton*)sender{
    [sat1 setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
    [sat setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
    
    [jiantouNormal setImage:[UIImage imageNamed:@"jiantou_normal"] forState:UIControlStateNormal];
    
    self.supField=@"new";
    searchBeans=nil;
    [self add];
}

-(void)sat1:(UIButton*)sender{
    saveAccount=!saveAccount;
    if (saveAccount) {
        
        self.supField=@"amount";
        _supSort=@"asc";
        
        [self add];
        [sat setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
        [sat1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [jiantouNormal setImage:[UIImage imageNamed:@"shang_hight"] forState:UIControlStateNormal];
        
    }else{
        
        self.supField=@"amount";
        
        _supSort=@"desc";
        [self add];
        [sat setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
        [sat1 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
        [jiantouNormal setImage:[UIImage imageNamed:@"xia_hight"] forState:UIControlStateNormal];
        
    }
}



//-(void)sat2:(UIButton*)sender{
//  self.supField=@"amount";
//    [self add];
//    [sat setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
//    [sat1 setTitleColor:[UIColor grayColor] forState:UIControlStateNormal];
//    [sat2 setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
//}

- (void)dateChanged:(id)sender
{
    
    UIDatePicker* picker = (UIDatePicker*)sender;
    NSDateFormatter* df = [[NSDateFormatter alloc] init];
    [df setDateFormat:@"yyyy-MM-dd"];
    
    if ([openTimeTextFied isFirstResponder])
    {
        openTimeTextFied.text = [NSString stringWithFormat:@"%@", [df stringFromDate:picker.date]];
        
        
        
    }else{
        
        closeTimeTextFied.text = [NSString stringWithFormat:@"%@", [df stringFromDate:picker.date]];
    }
    
    
}



- (void)showAlertWait
{
    alt = [[UIAlertView alloc] initWithTitle:@"网络不稳定 ！" message:@"请确认网络" delegate:self cancelButtonTitle:nil otherButtonTitles: nil];
    [alt show];
    
    [self performSelector:@selector(hideAlert) withObject:nil afterDelay:1.0f];
    
}

- (void)showAlertMessage:(NSString *)msg
{
    alt = [[UIAlertView alloc] initWithTitle:@"温馨提示" message:msg delegate:nil cancelButtonTitle:nil otherButtonTitles: nil];
    [alt show];
    
    [self performSelector:@selector(hideAlert) withObject:nil afterDelay:1.0f];
}
- (void)hideAlert
{
    if (alt != nil)
    {
        [alt dismissWithClickedButtonIndex:0 animated:YES];
        alt = nil;
    }
}



-(void)jiazai1{
    [jiazai removeFromSuperview];
    
    
}

@end
